﻿using System;
using System.Net.Http;
using Tavis.Interfaces;

namespace Tavis {


    public class Link : ILink  {
        public Uri Context { get; set; }
        public virtual string Relation { get; set; }
        public Uri Target { get; set; }
        public HttpMethod Method { get; set; }
        public HttpContent Content { get; set; }
        public StateChangeType StateChange { get; set; }
        public string Accept { get; set; }

        public Link() {
            Method = HttpMethod.Get;
            StateChange = StateChangeType.Transfer;
        }

        public Link(String target) : this(new Uri(target, UriKind.RelativeOrAbsolute)) {
        }

        public Link(Uri target) : this() {
            Target = target;
        }

        public Link(string relation, Uri context, Uri target ) {
            Method = HttpMethod.Get;
            Relation = relation;
            Context = context;
            Target = target;
            StateChange = StateChangeType.Transfer;
        }


        public void AddParameter(string key, object value) {
            Target = new Uri(Target.AbsoluteUri.Replace("%7B" + key + "%7D", value.ToString()));
        }

        public void AddDateParameter(string key, DateTime value) {
            AddParameter(key, value.ToString("yyy-MM-dd"));
        }
        public void AddDateTimeParameter(string key, DateTime value) {
            AddParameter(key, value.ToString("yyy-MM-ddTHH:mm:ss"));
        }


    }
}
